﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BattleThis.Core.Battle;
using BattleThis.Core.Movement;

namespace BattleThis.Core
{
	/// <summary>
	/// Service for units.
	/// </summary>
	public class UnitService
	{

		#region Variablen
		public const int InvalidId = -1;
		private int m_IdCounter = 0;
		#endregion

		#region Properties

		#endregion

		#region Methoden

		public Unit CreateTank()
		{
			var unit = new Unit( m_IdCounter++, UnitType.Tank );
			unit.Armor = new Armor(100);
			unit.Balance = Balance.Empty;
			unit.Weapon= new Weapon( 3, 35 );
			unit.Experience = new Experience();
			unit.ActionPoints = new ActionPoint( 2 );

			return unit;
		}

		public void SetUnits( Game game )
		{
			if( game == null )throw new ArgumentNullException( "game" );
			if( !game.IsReady() ) return;

            game.Map.RemoveUnites();

            foreach (var item in game.Players)
            {
                item.Army.Clear();    
            }

			game.Map.Fields[ 7, 6 ].Unit = this.CreateTank();
			game.Map.Fields[ 3, 4 ].Unit = this.CreateTank();

			game.Players.First().Army.Add( game.Map.Fields[ 7, 6 ].Unit );
			game.Players.Last().Army.Add( game.Map.Fields[ 3, 4 ].Unit );
		}

		#endregion

	}
}